﻿using System;
using SaiLing.Repository;

namespace SaiLing.SingleSignOn.Repository
{
    public class DatabaseFactory<T> : IDatabaseFactory<T>
    {
        private ProjectDbContext _dataContext;

        public BaseDbContext Get()
        {
            return _dataContext ?? (_dataContext = new ProjectDbContext());
        }

        private bool disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    _dataContext?.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

    }
}
